﻿
''' <summary>
''' Class Representing Buffering Parameters for a Zip File.
''' </summary>
Public Class Buffering
    'Shared :
    ''' <summary>
    ''' Default Buffering Definition.
    ''' </summary>
    Public Shared Defaults As Buffering
    Shared Sub New()
        Defaults = New Buffering
    End Sub
    'Ctor :
    ''' <summary>
    ''' Creates a new Buffering instance.
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub New()
        Me.Reset()
    End Sub
    'Fields :
    ''' <summary>
    ''' In / Out Buffer Size.
    ''' </summary>
    Public Property IOBS As Integer
    ''' <summary>
    ''' Zlib Codec Buffer Size.
    ''' </summary>
    Public Property ZCBS As Integer
    ''' <summary>
    ''' Parallel Deflate Threshold.
    ''' </summary>
    Public Property PDT As Long
    ''' <summary>
    ''' Parallel Deflate Maximum Buffer Pairs.
    ''' </summary>
    Public Property PDMBP As Integer
    'Routines :
    ''' <summary>
    ''' Reset Buffering to default.
    ''' </summary>
    Public Sub Reset()
        Me.IOBS = Zip.ZipFile.BufferSizeDefault
        Me.ZCBS = Zlib.ZlibConstants.WorkingBufferSizeDefault
        Me.PDT = 524288L
        Me.PDMBP = 16
    End Sub

    ''' <summary>
    ''' Resets a given property to its default value.
    ''' </summary>
    ''' <param name="propertyname">Property name to reset</param>
    Public Sub Reset(ByVal propertyname As String)
        Select Case propertyname
            Case "IOBS"
                Me.IOBS = Zip.ZipFile.BufferSizeDefault
            Case "ZCBS"
                Me.ZCBS = Zlib.ZlibConstants.WorkingBufferSizeDefault
            Case "PDT"
                Me.PDT = 524288L
            Case "PDMBP"
                Me.PDMBP = 16
        End Select
    End Sub

    ''' <summary>
    ''' Copies buffering values from another buffering object.
    ''' </summary>
    ''' <param name="buff">Buffering object from wich copy value</param>
    Public Sub CopyFrom(ByVal buff As Buffering)
        Me.IOBS = buff.IOBS
        Me.ZCBS = buff.ZCBS
        Me.PDT = buff.PDT
        Me.PDMBP = buff.PDMBP
    End Sub

    ''' <summary>
    ''' Applies buffering parameters to the given zip file.
    ''' </summary>
    ''' <param name="zip">zipFile instance</param>
    Public Sub ApplyToZip(ByVal zip As Zip.ZipFile)
        zip.BufferSize = Me.IOBS
        zip.CodecBufferSize = Me.ZCBS
        zip.ParallelDeflateThreshold = Me.PDT
        zip.ParallelDeflateMaxBufferPairs = Me.PDMBP
    End Sub

    ''' <summary>
    ''' Gets a string representation for buffering instance.
    ''' </summary>
    Public Function Infos() As String
        Return String.Format("Buffering : IOBS = {0} - ZCBS = {1} - PDT = {2} - PDMBP = {3}", _
                             StringFromSize(Me.IOBS, 0), StringFromSize(Me.ZCBS, 0), _
                             StringFromSize(Me.PDT, 0), Me.PDMBP)
    End Function

End Class

